package base.regex;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class 爬虫 {
    public static void main(String[] args) throws IOException {
        URL url = new URL("https://zhidao.baidu.com/question/697193277444573644.html");
        URLConnection conn = url.openConnection();
        BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        String line;
        String regex = ".歌..";
        //正则表达式对象
        Pattern pattern = Pattern.compile(regex);
        while ((line = br.readLine()) != null){
            //文本匹配器对象
            Matcher matcher = pattern.matcher(line);
            //System.out.println(line);
            while (matcher.find()){  //返回布尔类型
                System.out.println(matcher.group());//获取匹配字符
            }
        }
        br.close();//
    }
}
